package com.example.hdwx.myapplication.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.hdwx.myapplication.R;
import com.example.hdwx.myapplication.eneity.found_eneitys.FoundActivityEneity;
import com.example.hdwx.myapplication.eneity.found_eneitys.FoundCarouselEneity;
import com.example.hdwx.myapplication.eneity.found_eneitys.FoundShareEneity;
import com.example.hdwx.myapplication.eneity.found_eneitys.FoundTopicEneity;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.ColorPointHintView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hudongwx on 17-2-13.
 */

public class TheFoundAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    Context context;
    //活动区
    List<FoundActivityEneity> dataA = new ArrayList<>();
    //分享区
    List<FoundShareEneity> dataS = new ArrayList<>();
    //和话题区
    List<FoundTopicEneity> dataCT = new ArrayList<>();
    //轮播图
    List<FoundCarouselEneity> dataCE = new ArrayList<>();

    public TheFoundAdapter(Context context, List<FoundActivityEneity> dataA, List<FoundShareEneity> dataS, List<FoundTopicEneity> dataCT, List<FoundCarouselEneity> dataCE) {
        this.context = context;
        this.dataA = dataA;
        this.dataS = dataS;
        this.dataCT = dataCT;
        this.dataCE = dataCE;
    }

    @Override
    public int getItemViewType(int position){
        if(position == 0 ){
            return R.layout.commoon_rollpager_view;
        }else if (position ==1){
            //活动区
          return R.layout.found_activity_layout;
        }else if (position ==2){
            //分享家
          return R.layout.found_share_layout;
        }else{
            //话题区
           return R.layout.found_topic_layout;
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(viewType, parent, false);
        if (viewType == R.layout.commoon_rollpager_view){
            return new foundCarouseViewHolder(view);
        }else if (viewType == R.layout.found_activity_layout){
            //活动区
            return new foundActivityViewHolder(view);
        }else if (viewType == R.layout.found_share_layout){
            //分享家
            return new foundShareViewHolder(view);
        }else if(viewType == R.layout.found_topic_layout){
            //话题区
            return  new foundTopicViewHolder(view);
        }
        return  null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
           if (holder instanceof foundCarouseViewHolder){
               //图片轮播切换时间
               ((foundCarouseViewHolder) holder).rollPagerView.setPlayDelay(3000);
               // 设置图片轮播适配器
               ((foundCarouseViewHolder) holder).rollPagerView.setAdapter(new FoundRollPagerAdapter(dataCE, context));
               //设置图片轮播小圆点
               ((foundCarouseViewHolder) holder).rollPagerView.setHintView(new ColorPointHintView(context, Color.YELLOW, Color.WHITE));
           }else if (holder instanceof foundActivityViewHolder){
               RecyclerView.LayoutManager manager = new LinearLayoutManager(
                       context, LinearLayoutManager.HORIZONTAL, false
               );
               ((foundActivityViewHolder)holder).activityrecyclerview.setLayoutManager(manager);

               //适配
               FoundActivityAdapter adapter = new FoundActivityAdapter(context, dataA);
               ((foundActivityViewHolder)holder).activityrecyclerview.setAdapter(adapter);

           }else if (holder instanceof foundShareViewHolder){
               RecyclerView.LayoutManager manager = new LinearLayoutManager(
                       context, LinearLayoutManager.HORIZONTAL, false
               );
               ((foundShareViewHolder)holder).sharerecyclerView.setLayoutManager(manager);

               //适配
               FoundShareAdapter adapter = new FoundShareAdapter(context, dataS);
               ((foundShareViewHolder)holder).sharerecyclerView.setAdapter(adapter);

           }else if(holder instanceof foundTopicViewHolder){
               StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
              ((foundTopicViewHolder)holder).topicrecyclerview.setLayoutManager(manager);
               FoundTopicAdapter adapter = new FoundTopicAdapter(context, dataCT,2);
            ((foundTopicViewHolder)holder).topicrecyclerview.setAdapter(adapter);
           }
    }

    @Override
    public int getItemCount() {
        return 4;
    }

    //轮播图
    class foundCarouseViewHolder extends RecyclerView.ViewHolder{
        RollPagerView rollPagerView;
        public foundCarouseViewHolder(View itemView) {
            super(itemView);
            rollPagerView = (RollPagerView) itemView.findViewById(R.id.common_RollPageView);
        }
    }


    //活动区
    class foundActivityViewHolder extends RecyclerView.ViewHolder{
        RecyclerView activityrecyclerview;
        public foundActivityViewHolder(View itemView) {
            super(itemView);
        activityrecyclerview = (RecyclerView) itemView.findViewById(R.id.found_activity_recycler_view);
        }
    }

    //分享家
    class foundShareViewHolder extends RecyclerView.ViewHolder{
        RecyclerView sharerecyclerView;
        public foundShareViewHolder(View itemView){
            super(itemView);
            sharerecyclerView = (RecyclerView) itemView.findViewById(R.id.found_share_recyclerview);
        }
    }

    //话题区
    class foundTopicViewHolder extends RecyclerView.ViewHolder{
      RecyclerView topicrecyclerview;
        public foundTopicViewHolder(View itemView) {
            super(itemView);
            topicrecyclerview = (RecyclerView) itemView.findViewById(R.id.found_topic_recycler_view);
        }
    }
}
